﻿@using System.ComponentModel
@using AntDesign.Core
@using AntDesign.TableModels
@using System.Text.Json.Serialization

<Table TItem="Dictionary<string, object>" OnChange="HanleChange" DataSource="@data" Loading="data==null" ScrollX="1500"
    PageSize="5" Size="TableSize.Small">
    @foreach (var key in data?.FirstOrDefault()?.Keys.Take(10) ?? new string[0])
    {
        <PropertyColumn Filterable Sortable Property=@(c=>c[key]) Title="@key" />
    }
</Table>

@inject HttpClient httpClient;
@code {

    List<Dictionary<string, object>> data;

    string githubUrl = "https://api.github.com/repos/ant-design-blazor/ant-design-blazor/contributors?per_page=200";

    protected async Task HanleChange(QueryModel<Dictionary<string, object>> query)
    {
        try
        { 
            var options = new JsonSerializerOptions();
            options.Converters.Add(new DictionaryConverter());

            data = await httpClient.GetFromJsonAsync<List<Dictionary<string, object>>>(githubUrl, options);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
}